
export function nextTick(cb) {
    const callback = []

    let pending = false
    let timerFunc
    function flush() {
        callback.forEach(cb => cb())
        pending = false
    }
    if (Promise) {
        timerFunc = () => {
            Promise.resolve().then(flush)
        }
    } else if (MutationObserver) {
        let observer = new MutationObserver(flush)
        let textNode = document.createTextNode(1)
        observer.observe(textNode, {
            characterData: true
        })
        timerFunc = () =>
            (textNode.textContent = 2)

    } else if (setImmediate) {
        timerFunc = () => {
            setImmediate(flush)
        }
    }
    
    callback.push(cb)
    if (!pending) {
        timerFunc()
        pending = true
    }
}